package com.hxzy.commons.dao.impl;

import java.util.List;
import java.util.Map;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.hxzy.commons.dao.IAuthDao;
import com.hxzy.commons.model.CmsUser;
import com.hxzy.core.base.dao.impl.BaseDAO;
import com.hxzy.core.utils.PageParam;
import com.hxzy.core.utils.PageQuery;
import com.hxzy.core.utils.PageUtil;

@Repository 
public class AuthDaoImpl extends BaseDAO implements IAuthDao{
	public PageUtil getUserList(PageParam pageParam){
		PageQuery pq = new PageQuery(pageParam);
		Query query = null;
		query = this.getSession().createQuery(pageParam.getSearchSql());
		Map map =pageParam.getConditionMap(); 
		int i = 0;
		if(map.containsKey("prename"))
		{     
			query.setString(i++, "%"+(String)map.get("prename")+"%");
		} 
		if(map.containsKey("precomfrom"))
		{     
			query.setString(i++, "%"+(String)map.get("precomfrom")+"%");
		} 
		PageUtil pu = pq.getPageUtil(query,this.getSession());

		return pu;
	}
	public PageUtil getAccList(PageParam pageParam){
		PageQuery pq = new PageQuery(pageParam);
		Query query = null;
		query = this.getSession().createQuery(pageParam.getSearchSql());
		Map map =pageParam.getConditionMap(); 
		/*int i = 0;
		if(map.containsKey("userName"))
		{     
			query.setString(i++, "%"+(String)map.get("userName")+"%");
		}  */
		PageUtil pu = pq.getPageUtil(query,this.getSession());

		return pu;
	}
	public CmsUser getAccByUid(String uid){ 
		CmsUser obj = null; 
		String hql = "from CmsUser where loginid='" + uid + "'";
		List accList = this.findList(hql);
		
		if(null != accList && accList.size() > 0){
			obj = (CmsUser)accList.get(0); 
		}
		//logger.debug("obj==:" + obj);
		return obj;
	}
	@Override
	public PageUtil loadUserList(PageParam pageParam) {
		PageQuery pq = new PageQuery(pageParam);
		Query query = null;
		query = this.getSession().createQuery(pageParam.getSearchSql());
		Map map =pageParam.getConditionMap(); 
		int i = 0;
		if(map.containsKey("prename"))
		{     
			query.setString(i++, "%"+(String)map.get("prename")+"%");
		} 
		if(map.containsKey("precomfrom"))
		{     
			query.setString(i++, "%"+(String)map.get("precomfrom")+"%");
		} 
		PageUtil pu = pq.getPageUtil(query,this.getSession());
		return pu;
	}
	@Override
	public PageUtil loadOrgList(PageParam pageParam) {
		PageQuery pq = new PageQuery(pageParam);
		Query query = null;
		query = this.getSession().createQuery(pageParam.getSearchSql());
		Map map =pageParam.getConditionMap(); 
		int i = 0;
		if(map.containsKey("orgName"))
		{     
			query.setString(i++, "%"+(String)map.get("orgName")+"%");
		} 
	 
		PageUtil pu = pq.getPageUtil(query,this.getSession());
		return pu;
	}
	@Override
	public PageUtil loadRoleList(PageParam pageParam) {
		PageQuery pq = new PageQuery(pageParam);
		Query query = null;
		query = this.getSession().createQuery(pageParam.getSearchSql());
		Map map =pageParam.getConditionMap(); 
		int i = 0;
		if(map.containsKey("roleName"))
		{     
			query.setString(i++, "%"+(String)map.get("roleName")+"%");
		} 
		 
		PageUtil pu = pq.getPageUtil(query,this.getSession());
		return pu;
	}
	@Override
	public PageUtil loadPowerList(PageParam pageParam) {
		PageQuery pq = new PageQuery(pageParam);
		Query query = null;
		query = this.getSession().createQuery(pageParam.getSearchSql());
		Map map =pageParam.getConditionMap(); 
		int i = 0;
		if(map.containsKey("powerName"))
		{     
			query.setString(i++, "%"+(String)map.get("powerName")+"%");
		} 
		 
		PageUtil pu = pq.getPageUtil(query,this.getSession());
		return pu;
	}
}
